// conio.h
#pragma once
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>
int kbhit(void) {
    struct termios oldt, newt;
    int ch;
    int oldf;
    tcgetattr(STDIN_FILENO, &oldt);
    newt = oldt;
    newt.c_lflag &= ~(ICANON | ECHO);
    tcsetattr(STDIN_FILENO, TCSANOW, &newt);
    oldf = fcntl(STDIN_FILENO, F_GETFL, 0);
    fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);
    ch = getchar();
    tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
    fcntl(STDIN_FILENO, F_SETFL, oldf);
    if(ch != EOF)
    {
        ungetc(ch, stdin);
        return 1;
    }
    return 0;
}

int getche(void) {
     struct termios tm, tm_old;
     int fd = 0, ch;
     tcgetattr(fd, &tm);
     tm_old = tm;
     cfmakeraw(&tm);
     tcsetattr(fd, TCSANOW, &tm);
     ch = getchar();
     tcsetattr(fd, TCSANOW, &tm_old);
     // if(ch=='\b') printf("\b \b"); // Fxxk
     // else if(ch=='\r') printf("\n");
     // else putchar(ch);
     return ch;
}
